Imports System.Data.SqlClient

Public Class cls_config_usuariocolumna_

    Implements ICloneable

#Region "Variables ..."
    Private int_idusuario As Integer = 0
    Private str_modulo As String = ""
    Private str_columnas As String = ""
    Private str_columnasOrden As String = ""
    Private byt_xml As Byte()

    Private col_Items As Collections.Generic.List(Of cls_config_usuariocolumna_) = Nothing
#End Region

#Region "Propiedades ..."
    ReadOnly Property This
        Get
            Return Me
        End Get
    End Property
    ReadOnly Property ThisDescripcion As String
        Get
            Return Me.ToString
        End Get
    End Property
    ReadOnly Property pKey
        Get
            Return idusuario
        End Get
    End Property
    Property idusuario() As Integer
        Get
            idusuario = int_idusuario
        End Get
        Set(ByVal value As Integer)
            int_idusuario = value
        End Set
    End Property
    Property modulo() As String
        Get
            modulo = str_modulo
        End Get
        Set(ByVal value As String)
            str_modulo = value
        End Set
    End Property
    Property columnas() As String
        Get
            columnas = str_columnas
        End Get
        Set(ByVal value As String)
            str_columnas = value
        End Set
    End Property
    Property columnasOrden() As String
        Get
            columnasOrden = str_columnasOrden
        End Get
        Set(ByVal value As String)
            str_columnasOrden = value
        End Set
    End Property
    Property xml() As Byte()
        Get
            xml = byt_xml
        End Get
        Set(ByVal value As Byte())
            byt_xml = value
        End Set
    End Property

    Property Items() As Collections.Generic.List(Of cls_config_usuariocolumna_)
        Get
            Items = col_Items
        End Get
        Set(ByVal value As Collections.Generic.List(Of cls_config_usuariocolumna_))
            col_Items = value
        End Set
    End Property
#End Region

    Private Sub CargarColeccion(ByVal obj_Reader As SqlDataReader)
        col_Items = New Collections.Generic.List(Of cls_config_usuariocolumna_)
        While obj_Reader.Read()
            Dim Elemento As New cls_config_usuariocolumna_
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idusuario"))) = False Then
                Elemento.int_idusuario = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idusuario")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("modulo"))) = False Then
                Elemento.str_modulo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("modulo")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("columnas"))) = False Then
                Elemento.str_columnas = (obj_Reader.GetValue(obj_Reader.GetOrdinal("columnas")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("columnasorden"))) = False Then
                Elemento.str_columnasOrden = (obj_Reader.GetValue(obj_Reader.GetOrdinal("columnasorden")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("xml"))) = False Then
                byt_xml = TryCast((obj_Reader.GetValue(obj_Reader.GetOrdinal("xml"))), Byte())
            End If
            col_Items.Add(Elemento)
        End While
    End Sub

    Private Sub CargarVariables(ByVal obj_Reader As SqlDataReader)
        obj_Reader.Read()
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idusuario"))) = False Then
            int_idusuario = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idusuario")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("modulo"))) = False Then
            str_modulo = (obj_Reader.GetValue(obj_Reader.GetOrdinal("modulo")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("columnas"))) = False Then
            str_columnas = (obj_Reader.GetValue(obj_Reader.GetOrdinal("columnas")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("columnasorden"))) = False Then
            str_columnasOrden = (obj_Reader.GetValue(obj_Reader.GetOrdinal("columnasorden")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("xml"))) = False Then
            byt_xml = TryCast((obj_Reader.GetValue(obj_Reader.GetOrdinal("xml"))), Byte())
        End If
    End Sub

    Public Sub Nuevo()
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "config_usuariocolumna__Nuevo"
                .Parameters.Add("@idusuario", SqlDbType.Int).Value = int_idusuario
                .Parameters.Add("@modulo", SqlDbType.NVarChar).Value = str_modulo
                .Parameters.Add("@columnas", SqlDbType.NVarChar).Value = str_columnas
                .Parameters.Add("@columnasorden", SqlDbType.NVarChar).Value = str_columnasOrden
                .Parameters.Add("@xml", SqlDbType.Image).Value = byt_xml
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Crear el registro de config_usuariocolumna_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Modificar()
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "config_usuariocolumna__Modificar"
                .Parameters.Add("@idusuario", SqlDbType.Int).Value = int_idusuario
                .Parameters.Add("@modulo", SqlDbType.NVarChar).Value = str_modulo
                .Parameters.Add("@columnas", SqlDbType.NVarChar).Value = str_columnas
                .Parameters.Add("@columnasorden", SqlDbType.NVarChar).Value = str_columnasOrden
                .Parameters.Add("@xml", SqlDbType.Image).Value = byt_xml
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Modificar el registro de config_usuariocolumna_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    'Public Sub Eliminar()
    '    Dim obj_Conexion As New cls_Conexion
    '    Try
    '        obj_Conexion.Conectar()
    '        With obj_Conexion.obj_SqlCommand
    '            .CommandType = CommandType.StoredProcedure
    '            .Connection = obj_Conexion.obj_SqlConnection
    '            .CommandText = "config_usuariocolumna__Eliminar"
    '            .ExecuteNonQuery()
    '        End With
    '    Catch ex As SqlClient.SqlException
    '         Throw New Exception("Error al Eliminar el registro de config_usuariocolumna_." & Chr(13) & _
    '        "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
    '        "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
    '        "Descripción: " & ex.Message)
    '    Finally
    '        obj_Conexion.Desconectar()
    '        obj_Conexion = Nothing
    '    End Try
    'End Sub

    Public Function Buscarxidusuarioxmodulo(ByVal idusuario As Integer, ByVal modulo As String) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            Buscarxidusuarioxmodulo = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "config_usuariocolumna__Buscarxidusuarioxmodulo"
                .Parameters.Add("@idusuario", SqlDbType.Int).Value = idusuario
                .Parameters.Add("@modulo", SqlDbType.NVarChar).Value = modulo
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                Buscarxidusuarioxmodulo = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Buscarxidusuarioxmodulo el registro de config_usuariocolumna_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    'Public Function CargarTodos() As Boolean
    '    Dim obj_Conexion As New cls_Conexion
    '    Dim obj_Reader As SqlDataReader
    '    Try
    '        CargarTodos = False
    '        obj_Conexion.Conectar()
    '        With obj_Conexion.obj_SqlCommand
    '            .CommandType = CommandType.StoredProcedure
    '            .Connection = obj_Conexion.obj_SqlConnection
    '            .CommandText = "config_usuariocolumna__CargarTodos"
    '        End With
    '        obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
    '        If obj_Reader.HasRows Then
    '            CargarColeccion(obj_Reader)
    '            CargarTodos = True
    '        End If
    '    Catch ex As SqlClient.SqlException
    '         Throw New Exception("Error al CargarTodos los registros de config_usuariocolumna_." & Chr(13) & _
    '        "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
    '        "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
    '        "Descripción: " & ex.Message)
    '    Finally
    '        obj_Conexion.Desconectar()
    '        obj_Conexion = Nothing
    '        obj_Reader = Nothing
    '    End Try
    'End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj_config_usuariocolumna_Clon As New cls_config_usuariocolumna_
        obj_config_usuariocolumna_Clon.int_idusuario = Me.int_idusuario
        obj_config_usuariocolumna_Clon.str_modulo = Me.str_modulo
        obj_config_usuariocolumna_Clon.str_columnas = Me.str_columnas
        obj_config_usuariocolumna_Clon.str_columnasOrden = Me.str_columnasOrden
        obj_config_usuariocolumna_Clon.byt_xml = Me.byt_xml
        obj_config_usuariocolumna_Clon.col_Items = Me.col_Items
        Return obj_config_usuariocolumna_Clon
    End Function

End Class
